/**
 * Created by Administrator on 2018/5/8.
 */
/**
 * 接待服务中的车辆安排
 * Created by Administrator on 2018/4/28.
 */

define(function (require,exports,module) {
    var sTpl = require("./vehicleBase.html");
    require("./vehicleBase.css");

    var VueComponent = Vue.extend({
        template: sTpl,
        methods:{
            pickTime1:function (val) {
                this.disFormInline.carDate = val;
            },
            pickTime2:function (val) {
                this.disFormInline.returnTime = val;
            },
            findVehicleOfAppointment:function () {
                var $this = this;
                axios.get(basepath+"/api/appointment/findVehicleOfAppointment", {
                    params: {
                        appoUnit: $this.checkFormInline.appoUnit,
                            appoName:$this.checkFormInline.appoName,
                            appoPhoneNum:$this.checkFormInline.appoPhoneNum,
                            appoDate:$this.checkFormInline.appoDate
                    }
                }
                  ).then(function (response) {
                    $this.tableData=response.data.content;
                });
            },
            checkTheDocuments:function(scope){
                this.dialogFormVisible = true;
                this.disFormInline={};
                this.appointment = this.tableData[scope.$index];
                var $this = this;
                if(scope.row.vehicleDispatch){
                    $this.disFormInline=scope.row.vehicleDispatch;
                    $this.disFormInline.appoPhoneNum=scope.row.appoPhoneNum;
                }else {
                    $this.$refs["disFormInline"].resetFields();
                }
            },
            dispatchingClick:function(scope) {
                this.disFormInline={
                    appoPhoneNum:'',
                    transportDepartment:'',
                    proposer:'',
                    carDate:'',
                    oddNumber:'',
                    dispatchId:'',
                    startKilometre:'',
                    returnTime:'',
                    returnKilometre:'',
                    toll:'',
                    driver:'',
                    transportPeople:'',
                    carNumber:'',
                    oilMass:'',
                    oilMoney:''
                };
                this.appointment = this.tableData[scope.$index];
                this.$refs.baseTable.dialogFormVisible = true;
                var $this = this;
                if(scope.row.vehicleDispatch){
                    $this.disFormInline=scope.row.vehicleDispatch;
                }else {
                    $this.$refs["disFormInline"].resetFields();

                }
            },
            clear:function(){
                this.$refs.baseTable.dialogFormVisible = false;
                this.findVehicleOfAppointment();
            },
            saveClick:function(){
              var $this = this;
                this.$refs.disFormInline.validate(function(validate){
                    if(validate){
                        $this.appointment.vehicleDispatch=$this.disFormInline;
                        axios.post(basepath+'/api/vehicle/saveVehicle', $this.appointment)
                            .then(function (response) {
                                $this.$refs["disFormInline"].resetFields();
                                $this.findVehicleOfAppointment();
                                $this.$notify({
                                    title: '派单成功',
                                    message: '派单成功'
                                });
                            });
                        $this.$refs.baseTable.dialogFormVisible = false;
                    }else{
                        $this.$notify({
                            title: '派单失败',
                            message: '派单失败'
                        });
                        return  false;
                    }
                });

            }
        },
        mounted:function() {
        }
        ,data:function(){
            return {
                isSee:false,
                isDispatch:'',
                dialogFormVisible: false,
                dispatchingShow:false,
                checkFormInline: {
                    appoUnit:'',
                    appoName:'',
                    appoPhoneNum:'',
                    appoDate: ''
                },
                disFormInline: {
                    appoPhoneNum:'',
                    transportDepartment:'',
                    proposer:'',
                    carDate:'',
                    oddNumber:'',
                    dispatchId:'',
                    startKilometre:'',
                    returnTime:'',
                    returnKilometre:'',
                    toll:'',
                    driver:'',
                    transportPeople:'',
                    carNumber:'',
                    oilMass:'',
                    oilMoney:''
                },
                rules: {
                    transportDepartment: [
                        { required: true, message: '请输入用车部门', trigger: 'blur' },
                        { max: 20, message: '长度不超过20个字符', trigger: 'blur' }
                    ],
                    proposer: [
                        { required: true, message: '请输入申请人', trigger: 'blur' },
                        {max: 20, message: '长度不超过20个字符', trigger: 'blur' }
                    ],
                    carNumber: [
                        { required: true, message: '请输入出车号', trigger: 'blur' },
                        { max: 20, message: '长度不超过20个字符', trigger: 'blur' }
                    ],
                    driver: [
                        { required: true, message: '请输入驾驶员', trigger: 'blur' },
                        { max: 20, message: '长度不超过20个字符', trigger: 'blur' }
                    ],
                    startKilometre:[
                        { type:'number',required: true, message: '请输入合法的数字', trigger: 'blur' }
                    ],
                    returnKilometre: [
                        { type:'number',required: true, message: '请输入合法的数字', trigger: 'blur' },
                    ],
                    oilMass: [
                        { type:'number',required: true, message: '请输入合法的数字', trigger: 'blur' },
                    ],
                    oilMoney: [
                        { type:'number',required: true, message: '请输入合法的数字', trigger: 'blur' },
                    ],
                    toll: [
                        { type:'number',required: true, message: '请输入合法的数字', trigger: 'blur' },
                    ]
                },


                pickerOptions1: {
                    shortcuts: [{
                        text: '今天',
                        onClick:function(picker) {
                            picker.$emit('pick', new Date());
                        }
                    }, {
                        text: '昨天',
                        onClick:function(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24);
                            picker.$emit('pick', date);
                        }
                    }, {
                        text: '一周前',
                        onClick:function (picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', date);
                        }
                    }]
                },
                tableData: {}
            }
        },
        created:function (){
            this.findVehicleOfAppointment();

        },
        activated:function () {
            messages.$emit('change','车辆管理');
        }
    });
    module.exports = VueComponent;
})
